home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news
- From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
- Newsgroups: comp.lang.c++
- Subject: Re: C++ syntax
- Date: Mon, 22 Jan 1996 12:34:20 +0100
- Organization: Fachbereich Informatik, TH Darmstadt
- Message-ID: <3103763C.15FB7483@intellektik.informatik.th-darmstadt.de>
- References: <3102EDDA.45A6@tribeca.ios.com>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (X11; I; SunOS 4.1.3 sun4m)
-
- John Leonard wrote:
- >
- > In the book Borland C++ 4.5 Object-Oriented Programming by Ted Faison, Sam's Publishing, page
- > 603, there is an example using the Borland template class library. First, the idea is to instantiate
- > a class of type TListImp(from a template) and then instantiate an object of that type. And then to
- > instantiate a class of type TListIteratorImp from a template, and then to instantiate an object of
- > that type. The TListIterator object will be used to move through the TListImp object. The details
- > about these class templates are not what my question is about, but rather the syntax of one of the
- > lines in the program is:
- > TListIteratorImp<string> next(a); // where a is an object of type TListImp<string>
- > ...
- > while(next) // ??
- > ...
- > What does this line mean? How does it work?
- >
-
- Take a look at 'conversion operators'.
- The iterator class most likely provides an operator like
-
- operator bool () const { ... }
-
- or the appropriate {int,void*}-conversion. In that case 'while (next)'
- reads as 'while (next.operator bool())'. The operator returns true
- iff the actual position of the iterator points to a valid element, so
- the loop is executed until the actual position points to an invalid
- element.
-
- Enno
-